package com.sk.bilibili.tool;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.sk.bilibili.bean.*;
import com.sk.bilibili.service.*;
import com.sk.bilibili.utils.QueryWrapperUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author 邵康
 * @date 2021/12/8 12:03
 */
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class TidyNum {

    @Autowired
    private MemberService memberService;
    @Autowired
    private FocusService focusService;

    @Test
    void tidyFocusNum(){
        List<Member> list = memberService.list(null);
        for (Member member:list){
            QueryWrapper<Focus> queryWrapper = QueryWrapperUtils.eq("focus_id", member.getId());
            Member member1 = new Member();
            member1.setId(member.getId());
            member1.setFansNum(focusService.list(queryWrapper).size());
            memberService.updateById(member1);
        }
    }

    @Autowired
    private FavoritesService favoritesService;
    @Autowired
    private CollectService collectService;

    @Test
    void tidyCollect(){
        List<Favorites> list = favoritesService.list(null);
        for (Favorites favorites:list){
            QueryWrapper<Collect> queryWrapper = QueryWrapperUtils.eq("favorites_id", favorites.getId());
            Favorites favorites1 = new Favorites();
            favorites1.setId(favorites.getId());
            favorites1.setCount(collectService.list(queryWrapper).size());
            favoritesService.updateById(favorites1);
        }
    }

}
